<?php
$arrrole = $this->permission;
?>

<script type="text/javascript" src="<?= base_url() . 'resource/js/jquery.cookie.js' ?>" charset="utf-8"></script>
<script type="text/javascript" src="<?= base_url() . 'resource/js/layer/layer.js' ?>" charset="utf-8"></script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
          <h1><?=lang('menu_wjgl')?></h1>
          <?=$this->breadcrumb->generateHTML();?>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-list"></i><?=lang('menu_file_contract')?></h3>
          </div>
          <div class="panel-body">
            <!-- 合同上传权限 begin-->
            <?php if ($arrrole['Filemanage_upcont'] == 1) { ?>
            <div class="well" style="padding:0 19px;">
              <div class="row">
                <form action="<?= blang_url('files/Filemanage/uploadfiles') ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <input name="action" type="hidden" value="submit">
                            <input type="file" name="fileField" id="fileField" title="Select the file">
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="control-label"><?= lang('file_qsrbt') ?></label>
                            <input type="text" name="title" id="title">
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="control-label"><?= lang('file_contract') ?></label>
                             <select class="form-control" name="type" id="type">
                                <option value="7"><?= lang('file_contract') ?></option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group" style="padding-top:37px;">
                            <input class="btn btn-primary" type="button" name="btnSubmit" id="btnSubmit" value="<?= lang('file_qrsc') ?>"/>
                        </div>
                    </div>
                </form>
              </div>
            </div>
            <?php } ?>
           <!-- 合同上传权限 end -->
            <div class="well" style="padding:0 19px;">
              <div class="row">
                <form action="<?= blang_url('files/Filemanage/contract') ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="control-label"><?= lang('file_wjbt') ?></label>
                            <input class="form-control" type="text" id="saerchkeys" name="saerchkeys" size="60" value="<?= isset($_GET['keys']) ? $_GET['keys'] : '' ?>">
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group">
                            <label class="control-label"><?= lang('file_contract') ?></label>
                             <select class="form-control" name="saerchtype" id="saerchtype">
                                <option value="7"><?= lang('file_contract') ?></option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-4">
                        <div class="form-group" style="padding-top:37px;">
                            <input class="btn btn-primary" type="button" value="<?= lang('file_cx') ?>" id="searchbtn">
                        </div>
                    </div>
                </form>
              </div>
            </div>
            <div class="table-responsive">
                <table class="table table-bordered table-hover oms-table">
                  <thead>
                    <tr>
                        <th class="text-left">id</th>
                        <th class="text-left"><?= lang('file_addtime') ?></th>
                        <th class="text-left"><?= lang('file_adduser') ?></th>
                        <th class="text-right"><?= lang('file_bt') ?></th>
                        <th class="text-right"><?= lang('file_lx') ?></th>
                        <th class="text-right"><?= lang('file_cz') ?></th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php if($listss): foreach ($listss as $key=>$row):?>
                    <tr>
                        <td class="text-left"><?= $row['id'] ?></td>
                        <td class="text-left" data-url="<?= $row['filename'] ?>">
                            <?= (!empty($row['add_time'])) ? date('Y-m-d H:i:s', $row['add_time']) : '' ?>
                        </td>
                        <td class="text-left" data-url="<?= $row['filename'] ?>">
                            <?= (!empty($row['account'])) ? $row['account'] : '' ?>
                        </td>
                        <td class="text-right"><?= $row['title'] ?></td>
                        <td class="text-right"><?= $row['file_contract'] ?></td>
                        <td class="text-right">
                        <!-- 合同编辑权限 begin-->
                        <?php if ($arrrole['Filemanage_mdycont'] == 1) { ?>
                            <a href="javascript:void()" class="btn btn-primary btn-sm edit"
                               data-id="<?= $row['id'] ?>/7" title="<?= lang('public_editText') ?>"><i class="fa fa-edit"></i></a>
                        <?php } ?>
                        <!-- 合同编辑权限 end -->

                        <!-- 合同删除权限 begin-->
                        <?php if ($arrrole['Filemanage_delcont'] == 1) { ?>
                            <a href="javascript:void()" class="btn btn-danger btn-sm dell"
                               data-id="<?= $row['id'] ?>" onclick="return confirm('您确定要删除吗?')" title="<?= lang('public_sc') ?>"><i class="fa fa-trash-o"></i></a>
                        <?php } ?>
                        <!-- 合同删除权限 end -->
                        <a class="btn btn-oms btn-sm" href="<?= blang_url('files/Filemanage/downfile/' . $row['id']) ?>"><i class="fa fa-download"></i>&nbsp;<?= lang('public_xz') ?></a>
                        </td>
                    </tr>
                    <?php endforeach; else:?>
                        <tr><td colspan="6" class="emptyNumber"><?=lang('public_mygdsj')?>....</td></tr>
                    <?php endif; ?>
                </tbody>
                </table>
                <?php if($pageshow):?>
                <div class="page">
                    <?=$pageshow?>
                </div>
                <?php endif;?>
            </div>
          </div>
        </div>
    </div>
  <script type="text/javascript">
    $('#searchbtn').click(function () {
        var keys = $.trim($('#saerchkeys').val());
        if (keys == '') {
            layer.tips('亲，您还没有输入需要检索的内容哦', '#saerchkeys');
            $('#saerchkeys').focus();
        } else {
            window.location.href = "<?= blang_url('files/Filemanage/contract/')?>?keys=" + keys;
        }
    });

    //删除的
    $('.dell').click(function () {
        obj = $(this);
        var index = layer.confirm('您确认要删除么？', {
            btn: ['是的', '再考虑下'] //按钮
        }, function () {
            $.ajax({
                type: "POST",
                dataType: "text",
                data: {id: obj.attr('data-id')},
                url: "<?php echo(blang_url('files/Filemanage/ajax_del/'));?>",
                beforeSend: function () {

                },
                success: function (data) {
                    if (data == -1) {
                        layer.msg("您没有删除权限！");

                    } else if (data == 1) {

                        layer.msg("删除成功！");
                        window.location.href = location.href;
                    } else {
                        layer.msg("删除失败，请联系管理员！");
                    }
                }
            });
            layer.close(index);
        }, function () {

        });
    });

    //修改的
    $('.edit').click(function () {
        ids = $(this).attr('data-id');
        var url = "<?php echo(blang_url('files/Filemanage/ajax_update/'));?>/" + ids;
        layer.open({
            type: 2,
            title: '修改文件属性',
            shadeClose: true,
            shade: 0.8,
            area: ['480px', '215px'],
            content: url //iframe的url
        });


    });

    //文件上传
    $('#btnSubmit').click(function () {
        console.log($('#fileField'));
        if ($('#fileField').val() == '') {
            layer.tips('亲，您还没选择上传文件哦', '#fileField');
        }
        else if ($('#title').val() == '') {
            layer.tips('亲，标题不能为空哦', '#title');
            $('#title').focus();
        } else {
            if (ckType()) {
                layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
                $('#form1').submit();
            }

        }
    });


    $('#fileField').change(function () {
        ckType();
    });


    function ckType() {
        var filepath = $('#fileField').val();
        var extStart = filepath.lastIndexOf(".");
        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
 if (ext != ".DOC" && ext != ".DOCX" && ext != ".PDF" && ext != ".XLS" && ext != ".XLSX" && ext != ".RAR" && ext != ".ZIP") {
            layer.tips('亲，只能上传pdf,doc,docs,xls,xlsx,rar,zip类型的文件哦', '#fileField');
            return false;
        } else {
            return true;
        }
    }
    $('#title').blur(function () {
        ckTitleRepeat();
    });

    $('#type').change(function () {
        ckTitleRepeat();
    });
    //验证同一个用户和同一个类型下面有没有重名
    function ckTitleRepeat() {
        //alert($('#title').val());
        if ($.trim($('#title').val()) != '') {

            $.post("<?php echo(blang_url('files/Filemanage/ajax_ck_title/'));?>", {
                'title': $('#title').val(),
                'typeid': $('#type').val()
            }, function (result) {
                if (result > 0) {
                    var ll = layer.tips('亲，您在[' + $("#type").find("option:selected").text() + ']分类下已经有同名的文件咯！', '#title', {time: 100000});
                    $('#btnSubmit').attr("disabled", true);//设置不可提交数据
                } else {
                    $('#btnSubmit').removeAttr("disabled");//设置可提交数据
                    var ll = layer.tips('可以使用', '#title', {time: 100000});
                }
            });
        } else {
            layer.tips('亲，标题不能为空哦', '#title');
            $('#btnSubmit').removeAttr("disabled");//设置可提交数据
        }
    }
</script>

</div>